package com.ffapp.demo.chat.model;

import android.text.TextUtils;

import com.alibaba.fastjson.annotation.JSONField;
import com.ffapp.demo.bean.UserStateData;
import com.google.gson.Gson;

import java.util.Calendar;
import java.util.Date;

import my.TimeUtils;

public class ChatMsgListData {

    /**
     * id : f9c2b94e2892836ba2ebc42de2388c56
     * createBy : system
     * createUserName : system
     * createTime : 2020-12-23 15:16:02
     * updateBy : system
     * updateUserName : system
     * updateTime : 2020-12-23 15:16:02
     * alarmId : d9fed9e4f8084f63833eed7688a0cee6
     * type : text
     * content : 我觉得这样不可以123
     * attachment : null
     * sendUser : a6c5260fcc71d2a18ec7f5d52f1b96e5
     * sendUserName : admin
     * avatar : http://192.168.25.236/zd_user/UserHeader/2020/12/18/2125A0F82D8D46B7803521C729F34B32.jpg
     */

    public final static String TYPE_TEXT = "text",TYPE_IMAGE = "image",TYPE_VIDEO= "video",TYPE_AUDIO = "audio",TYPE_LOCATION = "position"
            ,TYPE_USERSTATE = "userstate";

    private String id;
    private String createBy;
    private String createUserName;
    private String createTime;
    private String updateBy;
    private String updateUserName;
    private String updateTime;
    private String alarmId;
    private String type;
    private String content;
    private String attachment;
    private String sendUser;
    private String sendUserName;
    private String avatar;
    private String positionName;
    private String positionAddress;
    private String positionImageUrl;

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getCreateBy() {
        return createBy;
    }

    public void setCreateBy(String createBy) {
        this.createBy = createBy;
    }

    public String getCreateUserName() {
        return createUserName;
    }

    public void setCreateUserName(String createUserName) {
        this.createUserName = createUserName;
    }

    public String getCreateTime() {
        return createTime;
    }

    public void setCreateTime(String createTime) {
        this.createTime = createTime;
    }

    public String getUpdateBy() {
        return updateBy;
    }

    public void setUpdateBy(String updateBy) {
        this.updateBy = updateBy;
    }

    public String getUpdateUserName() {
        return updateUserName;
    }

    public void setUpdateUserName(String updateUserName) {
        this.updateUserName = updateUserName;
    }

    public String getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(String updateTime) {
        this.updateTime = updateTime;
    }

    public String getAlarmId() {
        return alarmId;
    }

    public void setAlarmId(String alarmId) {
        this.alarmId = alarmId;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public String getAttachment() {
        return attachment;
    }

    public void setAttachment(String attachment) {
        this.attachment = attachment;
    }

    public String getSendUser() {
        return sendUser;
    }

    public void setSendUser(String sendUser) {
        this.sendUser = sendUser;
    }

    public String getSendUserName() {
        return sendUserName;
    }

    public void setSendUserName(String sendUserName) {
        this.sendUserName = sendUserName;
    }

    public String getAvatar() {
        return avatar;
    }

    public void setAvatar(String avatar) {
        this.avatar = avatar;
    }

    @JSONField(serialize = false)
    public String getTimeShow_STR(ChatMsgListData preData){
        if(TextUtils.isEmpty(createTime))return "";

        Calendar calendarTodayBegin = Calendar.getInstance();
        calendarTodayBegin.set(Calendar.HOUR_OF_DAY,0);
        calendarTodayBegin.set(Calendar.MINUTE,0);
        calendarTodayBegin.set(Calendar.SECOND,0);
        calendarTodayBegin.set(Calendar.MILLISECOND,0);
        Calendar calendarTodayEnd= Calendar.getInstance();
        calendarTodayEnd.set(Calendar.HOUR_OF_DAY,23);
        calendarTodayEnd.set(Calendar.MINUTE,59);
        calendarTodayEnd.set(Calendar.SECOND,59);
        calendarTodayEnd.set(Calendar.MILLISECOND,999);
        Date dateCreate = new Date(TimeUtils.getLongTimeByFormat(createTime,TimeUtils.TIME_FOMART));
        if(dateCreate.after(calendarTodayBegin.getTime()) && dateCreate.before(calendarTodayEnd.getTime())){
            //是今天的
            return TimeUtils.formatToFomat(createTime,TimeUtils.TIME_FOMART,"HH:mm");
        }else {
            return TimeUtils.formatToFomat(createTime,TimeUtils.TIME_FOMART,TimeUtils.TIME_FOMART_MINIT);
        }

//        long[] timeDisance = TimeUtils.getDistanceTimes(preData.getCreateTime(),createTime);
//        int dayCount = (int) timeDisance[0];
//        int hourCount = (int) timeDisance[1];
//        int minitCount = (int) timeDisance[2];
//        int secondCount = (int) timeDisance[3];
//        if(dayCount > 0){
//            if(dayCount > 2)return createTime;
//            if(dayCount == 2){
//                return "前天"+TimeUtils.formatToFomat(createTime,TimeUtils.TIME_FOMART,"HH:mm:ss");
//            }
//            if(dayCount == 1){
//                return "昨天"+TimeUtils.formatToFomat(createTime,TimeUtils.TIME_FOMART,"HH:mm:ss");
//            }
//            return  createTime;
//        }
//        if(hourCount > 0){
//
//            return TimeUtils.formatToFomat(createTime,TimeUtils.TIME_FOMART,"HH:mm:ss");
//        }
//        if(minitCount >5){
//            return TimeUtils.formatToFomat(createTime,TimeUtils.TIME_FOMART,"HH:mm:ss");
//        }
//        return "";
    }

    public String getPositionName() {
        return positionName;
    }

    public void setPositionName(String positionName) {
        this.positionName = positionName;
    }

    public String getPositionAddress() {
        return positionAddress;
    }

    public void setPositionAddress(String positionAddress) {
        this.positionAddress = positionAddress;
    }

    public String getPositionImageUrl() {
        return positionImageUrl;
    }

    public void setPositionImageUrl(String positionImageUrl) {
        this.positionImageUrl = positionImageUrl;
    }

    public String contentJsonToString(){
        Gson gson = new Gson();
        UserStateData userStateData = gson.fromJson(content, UserStateData.class);
        StringBuilder builder = new StringBuilder();
        builder.append("姓名：").append(userStateData.getUsername()).append("<br>")
                .append("单位：").append(userStateData.getDeptname()).append("<br>")
                .append("电话：").append(userStateData.getPhone()).append("<br>")
                .append("时间：").append(userStateData.getTime()).append("<br>")
                .append("内攻：").append(userStateData.getNeigong()).append("人").append("<br>")
                .append("搜救：").append(userStateData.getSoujiu()).append("人").append("<br>")
                .append("人员状态：");
        if(userStateData.getStatus().equals("正常")){
            builder.append("<font color=\"#00FF00\">").append(""+userStateData.getStatus()).append("</font>"); //绿色
        }else {
            builder.append(userStateData.getStatus());
        }

        ;
        return builder.toString();
    }
}
